<template>
    <div>
        <div>手机号：<input type="text" placeholder="请输入手机号" v-model="cellphone"></div>
        <div>密码：<input type="text" placeholder="请输入密码" v-model="password"></div>
        <div><button type="button" @click="submit()">注册</button></div>
    </div>
</template>

<script>
    import {mapActions} from "vuex";
  export default {
    name: 'reg',
    data(){
      return {
        cellphone:"",
        password:""
      }
    },
    methods:{
      ...mapActions({
        regUser:"user/regUser"
      }),
      submit(){
        if(this.cellphone.trim()==''){
          alert('请输入手机号');
          return
        }
        if(this.password.trim()==''){
          alert('请输入密码');
          return;
        }
        this.regUser({cellphone: this.cellphone,password:this.password,complete:(res)=>{
            if(res.code==200){
              this.$router.replace("/");
            }else{
              alert(res.data);
            }
          }
        });

      }
    }
  };
</script>

<style scoped>

</style>
